<!DOCTYPE html>
<html lang="en">

<!-- Head tag -->
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="null">
    <meta name="keyword" content="null">
    <meta name="theme-color" content="#600090">
    <meta name="msapplication-navbutton-color" content="#600090">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="#600090">
    <link rel="shortcut icon" href="/assets/favicon.ico">
    <link rel="alternate" type="application/atom+xml" title="张小阳" href="/atom.xml">
    <link rel="stylesheet" href="https://cdn.bootcss.com/animate.css/3.5.2/animate.css">
    <link rel="stylesheet" href="https://cdn.bootcss.com/font-awesome/4.6.3/css/font-awesome.css">
    <title>
        
        Vue备忘｜MillZhang&#39;s blog
        
    </title>

    <link rel="canonical" href="http://millzhang.github.io/2017/04/21/2017-note/03.Vue笔录/">

    <!-- Bootstrap Core CSS -->
    <link rel="stylesheet" href="/css/bootstrap.min.css">

    <!-- Custom CSS -->
    <link rel="stylesheet" href="/css/blog-style.css">

    <!-- Pygments Github CSS -->
    <link rel="stylesheet" href="/css/syntax.css">
</head>

<!-- hack iOS CSS :active style -->
<body ontouchstart="" class="animated fadeIn">
<!-- Navigation -->
<nav class="navbar navbar-default navbar-custom navbar-fixed-top " id="nav-top" data-ispost = "true" data-istags="false
" data-ishome = "false" >
    <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header page-scroll">
            <button type="button" class="navbar-toggle">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand animated pulse" href="/">
                <span class="brand-logo">
                    MillZhang
                </span>
            </a>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <!-- Known Issue, found by Hux:
            <nav>'s height woule be hold on by its content.
            so, when navbar scale out, the <nav> will cover tags.
            also mask any touch event of tags, unfortunately.
        -->
        <!-- /.navbar-collapse -->
        <div id="huxblog_navbar">
            <div class="navbar-collapse">
                <ul class="nav navbar-nav navbar-right">
                    <li>
                        <a href="/"><i class="fa fa-home"></i>主页</a>
                    </li>
                   <li>
                        <a href="/tags"><i class="fa fa-tags"></i>归档</a>
                    </li>
                    <li>
                        <a href="/about"><i class="fa fa-user"></i>关于</a>
                    </li>
                </ul>
            </div>
        </div>
    </div>
    <!-- /.container -->
</nav>
<script>
    // Drop Bootstarp low-performance Navbar
    // Use customize navbar with high-quality material design animation
    // in high-perf jank-free CSS3 implementation
//    var $body   = document.body;
    var $toggle = document.querySelector('.navbar-toggle');
    var $navbar = document.querySelector('#huxblog_navbar');
    var $collapse = document.querySelector('.navbar-collapse');

    $toggle.addEventListener('click', handleMagic)
    function handleMagic(e){
        if ($navbar.className.indexOf('in') > 0) {
        // CLOSE
            $navbar.className = " ";
            // wait until animation end.
            setTimeout(function(){
                // prevent frequently toggle
                if($navbar.className.indexOf('in') < 0) {
                    $collapse.style.height = "0px"
                }
            },400)
        }else{
        // OPEN
            $collapse.style.height = "auto"
            $navbar.className += " in";
        }
    }
</script>

<!-- Main Content -->

<!--only post-->

<header class="intro-header">
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1 text-center">
                <div class="post-heading">
                    <h1>Vue备忘</h1>
                    
                    <span class="meta">
                         作者 MillZhang
                        <span>
                          日期 2017-04-21
                         </span>
                    </span>
                    <div class="tags text-center">
                        
                        <a class="tag" href="/tags/#vue"
                           title="vue">vue</a>
                        
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="post-title-haojen">
        <span>
            Vue备忘
        </span>
    </div>
    <div class="post-header-image">
        
            <img src="http://oritfw5nq.bkt.clouddn.com/wall-303.jpg?imageView2/0/format/jpg/interlace/1/q/85|watermark/2/text/QnkgTWlsbHpoYW5n/font/5b6u6L2v6ZuF6buR/fontsize/480/fill/I0ZERkRGRA==/dissolve/56/gravity/SouthEast/dx/10/dy/10|imageslim">
         
    </div>
</header>

<!-- Post Content -->
<article>
    <div class="container">
        <div class="row">
            <!-- Post Container -->
            <div class="col-lg-8 col-lg-offset-1 col-sm-9 post-container">
                <h3 id="keep-alive"><a href="#keep-alive" class="headerlink" title="keep-alive"></a><a href="http://www.jianshu.com/p/42429f4d8f9e?nomobile=yes" target="_blank" rel="external">keep-alive</a></h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">&lt;router-view keep-alive&gt;&lt;/router-view&gt;</div><div class="line"></div><div class="line">&lt;keep-alive&gt;</div><div class="line">  &lt;router-view&gt;&lt;/router-view&gt;</div><div class="line">&lt;/keep-alive&gt;</div></pre></td></tr></table></figure>
<blockquote>
<p>页面第一次进入，钩子的触发顺序created-&gt; mounted-&gt; activated，退出时触发deactivated</p>
</blockquote>
<h3 id="vue-router之redirect"><a href="#vue-router之redirect" class="headerlink" title="vue-router之redirect"></a>vue-router之redirect</h3><figure class="highlight js"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">const</span> routes = [</div><div class="line">  &#123;<span class="attr">path</span>: baseUrl + <span class="string">'/'</span>, <span class="attr">redirect</span>: baseUrl + <span class="string">'/home'</span>&#125;,<span class="comment">//空路径重定向到home页</span></div><div class="line">  &#123;<span class="attr">path</span>: baseUrl + <span class="string">'/home'</span>, <span class="attr">component</span>: homeCpm&#125;,</div><div class="line">  &#123;<span class="attr">path</span>: baseUrl + <span class="string">'/startdemo'</span>, <span class="attr">component</span>: startCpm&#125;,</div><div class="line">  &#123;<span class="attr">path</span>: <span class="string">'*'</span>, <span class="attr">component</span>: errorCpm&#125;<span class="comment">//匹配不到的路径,跳转至错误页面404</span></div><div class="line">]</div></pre></td></tr></table></figure>
<h3 id="HtmlWebpackPlugin"><a href="#HtmlWebpackPlugin" class="headerlink" title="HtmlWebpackPlugin"></a><a href="http://www.cnblogs.com/haogj/p/5160821.html" target="_blank" rel="external">HtmlWebpackPlugin</a></h3><blockquote>
<p>用来简化创建服务于 webpack bundle 的 HTML 文件，尤其是对于在文件名中包含了 hash 值，而这个值在每次编译的时候都发生变化的情况。你既可以让这个插件来帮助你自动生成 HTML 文件，也可以使用 lodash 模板加载生成的 bundles，或者自己加载这些 bundles。</p>
</blockquote>
<h4 id="示例"><a href="#示例" class="headerlink" title="示例"></a>示例</h4><hr>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">new HtmlWebpackPlugin(&#123;</div><div class="line">    filename: &apos;index.html&apos;,</div><div class="line">    template: &apos;index.html&apos;,</div><div class="line">    inject: true</div><div class="line">&#125;),</div></pre></td></tr></table></figure>
<h4 id="参数"><a href="#参数" class="headerlink" title="参数"></a>参数</h4><hr>
<ul>
<li>title: 用来生成页面的 title 元素</li>
<li>filename: 输出的 HTML 文件名，默认是 index.html, 也可以直接配置带有子目录。</li>
<li>template: 模板文件路径，支持加载器，比如 html!./index.html</li>
<li>inject: true | ‘head’ | ‘body’ | false  ,注入所有的资源到特定的 template 或者 templateContent 中，如果设置为 true 或者 body，所有的 javascript 资源将被放置到 body 元素的底部，’head’ 将放置到 head 元素中。</li>
<li>favicon: 添加特定的 favicon 路径到输出的 HTML 文件中。</li>
<li>minify: {} | false , 传递 html-minifier 选项给 minify 输出</li>
<li>hash: true | false, 如果为 true, 将添加一个唯一的 webpack 编译 hash 到所有包含的脚本和 CSS 文件，对于解除 cache 很有用。</li>
<li>cache: true | false，如果为 true, 这是默认值，仅仅在文件修改之后才会发布文件</li>
<li>showErrors: true | false, 如果为 true, 这是默认值，错误信息会写入到 HTML 页面中</li>
<li>chunks: 允许只添加某些块 (比如，仅仅 unit test 块)</li>
<li>chunksSortMode: 允许控制块在添加到页面之前的排序方式，支持的值：’none’ | ‘default’ | {function}-default:’auto’</li>
<li>excludeChunks: 允许跳过某些块，(比如，跳过单元测试的块)</li>
</ul>
<h3 id="Transitions-组件"><a href="#Transitions-组件" class="headerlink" title="Transitions 组件"></a><a href="https://cn.vuejs.org/v2/guide/transitions.html" target="_blank" rel="external">Transitions 组件</a></h3><h4 id="主要功能"><a href="#主要功能" class="headerlink" title="主要功能"></a>主要功能</h4><hr>
<ul>
<li>在 CSS 过渡和动画中自动应用 class</li>
<li>可以配合使用第三方 CSS 动画库，如 Animate.css</li>
<li>在过渡钩子函数中使用 JavaScript 直接操作 DOM</li>
<li>可以配合使用第三方 JavaScript 动画库，如 Velocity.js</li>
</ul>
<h4 id="示例-1"><a href="#示例-1" class="headerlink" title="示例"></a>示例</h4><hr>
<figure class="highlight html"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line"><span class="tag">&lt;<span class="name">transition</span> <span class="attr">name</span>=<span class="string">"slide-fade"</span>&gt;</span></div><div class="line">  <span class="tag">&lt;<span class="name">router-view</span> <span class="attr">keep-alive</span>&gt;</span><span class="tag">&lt;/<span class="name">router-view</span>&gt;</span></div><div class="line"><span class="tag">&lt;/<span class="name">transition</span>&gt;</span></div></pre></td></tr></table></figure>
<figure class="highlight css"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line"><span class="selector-class">.slide-fade-enter-active</span> &#123;</div><div class="line">  <span class="attribute">transition</span>: all .<span class="number">4s</span> ease;</div><div class="line">&#125;</div><div class="line"><span class="selector-class">.slide-fade-leave-active</span> &#123;</div><div class="line">  <span class="comment">/*transition: all 0.1s cubic-bezier(1.0, 0.5, 0.8, 1.0);*/</span></div><div class="line">&#125;</div><div class="line"><span class="selector-class">.slide-fade-enter</span>, <span class="selector-class">.slide-fade-leave-active</span> &#123;</div><div class="line">  <span class="attribute">transform</span>: <span class="built_in">translateX</span>(150px);</div><div class="line">  <span class="attribute">opacity</span>: <span class="number">0</span>;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h4 id="过渡的css类名"><a href="#过渡的css类名" class="headerlink" title="过渡的css类名"></a>过渡的css类名</h4><hr>
<ol>
<li>v-enter: 定义进入过渡的开始状态。在元素被插入时生效，在下一个帧移除。</li>
<li>v-enter-active: 定义进入过渡的结束状态。在元素被插入时生效，在 transition/animation 完成之后移除。</li>
<li>v-leave: 定义离开过渡的开始状态。在离开过渡被触发时生效，在下一个帧移除。</li>
<li>v-leave-active: 定义离开过渡的结束状态。在离开过渡被触发时生效，在 transition/animation 完成之后移除。<br><img src="https://cn.vuejs.org/images/transition.png" alt="image"><blockquote>
<p>对于这些在 enter/leave 过渡中切换的类名，v- 是这些类名的前缀。使用 <transition name="my-transition"> 可以重置前缀，比如 v-enter 替换为 my-transition-enter。<br>v-enter-active 和 v-leave-active 可以控制 进入/离开 过渡的不同阶段</transition></p>
</blockquote>
</li>
</ol>
<h4 id="自定义过渡类名"><a href="#自定义过渡类名" class="headerlink" title="自定义过渡类名"></a>自定义过渡类名</h4><hr>
<ul>
<li>enter-class</li>
<li>enter-active-class</li>
<li>leave-class</li>
<li>leave-active-class</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">&lt;transition</div><div class="line">    name=&quot;custom-classes-transition&quot;</div><div class="line">    enter-active-class=&quot;animated tada&quot;</div><div class="line">    leave-active-class=&quot;animated bounceOutRight&quot;&gt;</div><div class="line">&lt;p v-if=&quot;show&quot;&gt;hello&lt;/p&gt;</div><div class="line">&lt;/transition&gt;</div></pre></td></tr></table></figure>
<h4 id="挂载javascript钩子"><a href="#挂载javascript钩子" class="headerlink" title="挂载javascript钩子"></a>挂载javascript钩子</h4><hr>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line">&lt;transition</div><div class="line">  v-on:before-enter=&quot;beforeEnter&quot;</div><div class="line">  v-on:enter=&quot;enter&quot;</div><div class="line">  v-on:after-enter=&quot;afterEnter&quot;</div><div class="line">  v-on:enter-cancelled=&quot;enterCancelled&quot;</div><div class="line">  v-on:before-leave=&quot;beforeLeave&quot;</div><div class="line">  v-on:leave=&quot;leave&quot;</div><div class="line">  v-on:after-leave=&quot;afterLeave&quot;</div><div class="line">  v-on:leave-cancelled=&quot;leaveCancelled&quot;</div><div class="line">&gt;</div><div class="line">  &lt;!-- ... --&gt;</div><div class="line">&lt;/transition&gt;</div></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div></pre></td><td class="code"><pre><div class="line">// ...</div><div class="line">methods: &#123;</div><div class="line">  // --------</div><div class="line">  // 进入中</div><div class="line">  // --------</div><div class="line">  beforeEnter: function (el) &#123;</div><div class="line">    // ...</div><div class="line">  &#125;,</div><div class="line">  // 此回调函数是可选项的设置</div><div class="line">  // 与 CSS 结合时使用</div><div class="line">  enter: function (el, done) &#123;</div><div class="line">    // ...</div><div class="line">    done()</div><div class="line">  &#125;,</div><div class="line">  afterEnter: function (el) &#123;</div><div class="line">    // ...</div><div class="line">  &#125;,</div><div class="line">  enterCancelled: function (el) &#123;</div><div class="line">    // ...</div><div class="line">  &#125;,</div><div class="line">  // --------</div><div class="line">  // 离开时</div><div class="line">  // --------</div><div class="line">  beforeLeave: function (el) &#123;</div><div class="line">    // ...</div><div class="line">  &#125;,</div><div class="line">  // 此回调函数是可选项的设置</div><div class="line">  // 与 CSS 结合时使用</div><div class="line">  leave: function (el, done) &#123;</div><div class="line">    // ...</div><div class="line">    done()</div><div class="line">  &#125;,</div><div class="line">  afterLeave: function (el) &#123;</div><div class="line">    // ...</div><div class="line">  &#125;,</div><div class="line">  // leaveCancelled 只用于 v-show 中</div><div class="line">  leaveCancelled: function (el) &#123;</div><div class="line">    // ...</div><div class="line">  &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h4 id="To-Learn-More"><a href="#To-Learn-More" class="headerlink" title="To Learn More"></a><a href="https://cn.vuejs.org/v2/guide/transitions.html#初始渲染的过渡" target="_blank" rel="external">To Learn More</a></h4><h3 id="FLIP-简单的动画队列"><a href="#FLIP-简单的动画队列" class="headerlink" title="FLIP 简单的动画队列"></a><a href="https://aerotwist.com/blog/flip-your-animations/" target="_blank" rel="external">FLIP 简单的动画队列</a></h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">//TODO</div></pre></td></tr></table></figure>
<h3 id="require-ensure和require-amd的区别"><a href="#require-ensure和require-amd的区别" class="headerlink" title="require-ensure和require-amd的区别"></a><a href="http://blog.csdn.net/zhbhun/article/details/46826129" target="_blank" rel="external">require-ensure和require-amd的区别</a></h3><h4 id="require-amd"><a href="#require-amd" class="headerlink" title="require-amd"></a>require-amd</h4><blockquote>
<p>说明: 同AMD规范的require函数，使用时传递一个模块数组和回调函数，模块都被下载下来且都被执行后才执行回调函数</p>
<p>语法: require(dependencies: String[], [callback: function(…)])</p>
<p>参数</p>
<ul>
<li>dependencies: 模块依赖数组</li>
<li>callback: 回调函数</li>
</ul>
</blockquote>
<hr>
<h4 id="require-ensure"><a href="#require-ensure" class="headerlink" title="require-ensure"></a>require-ensure</h4><blockquote>
<p>说明: require.ensure在需要的时候才下载依赖的模块，当参数指定的模块都下载下来了（下载下来的模块还没执行），便执行参数指定的回调函数。require.ensure会创建一个chunk，且可以指定该chunk的名称，如果这个chunk名已经存在了，则将本次依赖的模块合并到已经存在的chunk中，最后这个chunk在webpack构建的时候会单独生成一个文件。</p>
<p>语法: require.ensure(dependencies: String[], callback: function([require]), [chunkName: String])</p>
<p>参数</p>
<ul>
<li>dependencies: 依赖的模块数组</li>
<li>callback: 回调函数，该函数调用时会传一个require参数</li>
<li>chunkName: 模块名，用于构建时生成文件时命名使用</li>
</ul>
</blockquote>
<h3 id="Vue监听页面滚动事件"><a href="#Vue监听页面滚动事件" class="headerlink" title="Vue监听页面滚动事件"></a>Vue监听页面滚动事件</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">import</span> &#123; mapState &#125; <span class="keyword">from</span> <span class="string">'vuex'</span></div><div class="line"><span class="keyword">export</span> <span class="keyword">default</span> &#123;</div><div class="line">  data()&#123;</div><div class="line">    <span class="keyword">return</span>&#123;</div><div class="line">      <span class="attr">scrolled</span>:<span class="literal">false</span></div><div class="line">    &#125;</div><div class="line">  &#125;,</div><div class="line">  <span class="attr">name</span>: <span class="string">'app'</span>,</div><div class="line">  <span class="attr">computed</span>: &#123;</div><div class="line">    ...mapState([<span class="string">'title'</span>, <span class="string">'urlItems'</span>])</div><div class="line">  &#125;,</div><div class="line">  <span class="attr">methods</span>:&#123;</div><div class="line">    handleScroll()&#123;</div><div class="line">      <span class="built_in">console</span>.log(<span class="built_in">window</span>.scrollY)</div><div class="line">    &#125;</div><div class="line">  &#125;,</div><div class="line">  mounted()&#123;<span class="comment">//vue2.0废弃了ready</span></div><div class="line">    <span class="built_in">window</span>.addEventListener(<span class="string">'scroll'</span>,<span class="keyword">this</span>.handleScroll)</div><div class="line">  &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h3 id="chrome滚动条美化"><a href="#chrome滚动条美化" class="headerlink" title="chrome滚动条美化"></a>chrome滚动条美化</h3><figure class="highlight css"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div></pre></td><td class="code"><pre><div class="line"><span class="selector-pseudo">::-webkit-scrollbar</span> &#123;</div><div class="line">    <span class="attribute">width</span>: <span class="number">8px</span>;</div><div class="line">    <span class="attribute">height</span>: <span class="number">8px</span>;</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="selector-pseudo">::-webkit-scrollbar-thumb</span><span class="selector-pseudo">:hover</span> &#123;</div><div class="line">    <span class="attribute">border</span>: <span class="number">1px</span> solid <span class="number">#636363</span>;</div><div class="line">    <span class="attribute">background-color</span>: <span class="number">#929292</span>;</div><div class="line">&#125;</div><div class="line"><span class="selector-pseudo">::-webkit-scrollbar-thumb</span> &#123;</div><div class="line">    <span class="attribute">background-color</span>: <span class="number">#c2c2c2</span>;</div><div class="line">    <span class="attribute">background-clip</span>: padding-box;</div><div class="line">    <span class="attribute">border</span>: <span class="number">1px</span> solid <span class="number">#979797</span>;</div><div class="line">    <span class="attribute">min-height</span>: <span class="number">10px</span>;</div><div class="line">    <span class="attribute">border-radius</span>: <span class="number">4px</span>;</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="selector-pseudo">::-webkit-scrollbar-track-piece</span> &#123;</div><div class="line">    <span class="attribute">background-color</span>: <span class="number">#f5f5f5</span>;</div><div class="line">    <span class="attribute">border-left</span>: <span class="number">1px</span> solid <span class="number">#d2d2d2</span>;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h3 id="vue部署刷新页面404"><a href="#vue部署刷新页面404" class="headerlink" title="vue部署刷新页面404"></a>vue部署刷新页面404</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">//解决方案1,去除history mode</div><div class="line">const router = new VueRouter(&#123;</div><div class="line">  hashbang: false, // 将路径格式化为#!开头</div><div class="line">  history: false, // use history=false when testing</div><div class="line">  // mode: &apos;history&apos;,</div><div class="line">  base: __dirname,</div><div class="line">  linkActiveClass: &apos;v-link-active&apos;,</div><div class="line">  routes // （缩写）相当于 routes: routes</div><div class="line">&#125;)</div></pre></td></tr></table></figure>
<h3 id="vue的跳转"><a href="#vue的跳转" class="headerlink" title="vue的跳转"></a>vue的跳转</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">&lt;router-link to=&quot;detail&quot;&gt;产品详情&lt;/router-link&gt;</div></pre></td></tr></table></figure>
<h3 id="vue设置html标题"><a href="#vue设置html标题" class="headerlink" title="vue设置html标题"></a>vue设置html标题</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line">//router有name属性</div><div class="line">const routeArray = [&#123;</div><div class="line">  path: BasePath + &apos;/&apos;,</div><div class="line">  redirect: &apos;/home&apos;</div><div class="line">&#125;, &#123;</div><div class="line">  path: BasePath + &apos;/home&apos;,</div><div class="line">  name: &apos;分享&apos;,</div><div class="line">  component: Home</div><div class="line">&#125;]</div><div class="line">//拦截router跳转</div><div class="line">router.afterEach(transition =&gt; &#123;</div><div class="line">  if (transition.name) &#123;</div><div class="line">    document.title = transition.name;</div><div class="line">  &#125;</div><div class="line">&#125;)</div></pre></td></tr></table></figure>
<h3 id="获取当前组件的元素"><a href="#获取当前组件的元素" class="headerlink" title="获取当前组件的元素"></a>获取当前组件的元素</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">this.$el</div></pre></td></tr></table></figure>
<h3 id="VUE在IOS上页面滑动不流畅的问题"><a href="#VUE在IOS上页面滑动不流畅的问题" class="headerlink" title="VUE在IOS上页面滑动不流畅的问题"></a>VUE在IOS上页面滑动不流畅的问题</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">//在可视区域的拖拽位置加入如下代码</div><div class="line">   -webkit-overflow-scrolling : touch;</div></pre></td></tr></table></figure>
<h3 id="vuex在ie9上报错"><a href="#vuex在ie9上报错" class="headerlink" title="vuex在ie9上报错"></a>vuex在ie9上报错</h3><p>错误 :<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[vuex] vuex requires a Promise polyfill in this browser.</div></pre></td></tr></table></figure></p>
<p>解决方案:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">npm install --save-dev babel-polyfill</div></pre></td></tr></table></figure></p>
<p>在webpack.config.js配置<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">module.exports = &#123;</div><div class="line">  entry: &#123;</div><div class="line">    app: [&apos;babel-polyfill&apos;,&apos;./src/main.js&apos;]</div><div class="line">  &#125;,</div><div class="line">&#125;;</div></pre></td></tr></table></figure></p>
<h3 id="vue-router去除’-’"><a href="#vue-router去除’-’" class="headerlink" title="vue-router去除’#’"></a><code>vue-router</code>去除’#’</h3><ol>
<li>开启html history模式<code>mode:history</code></li>
<li>ngnix rewrite url<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div></pre></td><td class="code"><pre><div class="line">location / &#123;</div><div class="line">  if (!-e $request_filename) &#123;</div><div class="line">          rewrite  ^(.*)$  /index.html?s=$1  last;</div><div class="line">          break;</div><div class="line">  &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
</li>
</ol>
<h3 id="vue监听对象属性的变化"><a href="#vue监听对象属性的变化" class="headerlink" title="vue监听对象属性的变化"></a><code>vue</code>监听对象属性的变化</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">watch: &#123;</div><div class="line">  imageList: &#123;</div><div class="line">    handler(newVal) &#123;</div><div class="line">      console.log(newVal)</div><div class="line">    &#125;,</div><div class="line">    deep: true</div><div class="line">  &#125;</div><div class="line">&#125;,</div></pre></td></tr></table></figure>

                <hr>
                <ul class="pager">
                    
                    <li class="previous">
                        <a href="/2017/05/01/2017-note/04.nodejs基础/" data-toggle="tooltip" data-placement="top"
                           title="Node.js 基础篇笔记">&larr; 上一页</a>
                    </li>
                    
                    
                    <li class="next">
                        <a href="/2017/04/13/2017-note/02.移动端坑和解决方案/" data-toggle="tooltip" data-placement="top"
                           title="移动端的坑和解决方案">下一页 &rarr;</a>
                    </li>
                    
                </ul>
                <div class="comment">
                    <div id="cloud-tie-wrapper" class="cloud-tie-wrapper"></div>
                </div>
            </div>
            <div class="hidden-xs col-sm-3 toc-col">
                <div class="toc-wrap">
                    <ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#keep-alive"><span class="toc-text">keep-alive</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#vue-router之redirect"><span class="toc-text">vue-router之redirect</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#HtmlWebpackPlugin"><span class="toc-text">HtmlWebpackPlugin</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#示例"><span class="toc-text">示例</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#参数"><span class="toc-text">参数</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Transitions-组件"><span class="toc-text">Transitions 组件</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#主要功能"><span class="toc-text">主要功能</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#示例-1"><span class="toc-text">示例</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#过渡的css类名"><span class="toc-text">过渡的css类名</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#自定义过渡类名"><span class="toc-text">自定义过渡类名</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#挂载javascript钩子"><span class="toc-text">挂载javascript钩子</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#To-Learn-More"><span class="toc-text">To Learn More</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#FLIP-简单的动画队列"><span class="toc-text">FLIP 简单的动画队列</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#require-ensure和require-amd的区别"><span class="toc-text">require-ensure和require-amd的区别</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#require-amd"><span class="toc-text">require-amd</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#require-ensure"><span class="toc-text">require-ensure</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Vue监听页面滚动事件"><span class="toc-text">Vue监听页面滚动事件</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#chrome滚动条美化"><span class="toc-text">chrome滚动条美化</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#vue部署刷新页面404"><span class="toc-text">vue部署刷新页面404</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#vue的跳转"><span class="toc-text">vue的跳转</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#vue设置html标题"><span class="toc-text">vue设置html标题</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#获取当前组件的元素"><span class="toc-text">获取当前组件的元素</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#VUE在IOS上页面滑动不流畅的问题"><span class="toc-text">VUE在IOS上页面滑动不流畅的问题</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#vuex在ie9上报错"><span class="toc-text">vuex在ie9上报错</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#vue-router去除’-’"><span class="toc-text">vue-router去除’#’</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#vue监听对象属性的变化"><span class="toc-text">vue监听对象属性的变化</span></a></li></ol>
                </div>
            </div>
        </div>

        <div class="row">
            <!-- Sidebar Container -->

            <div class="
                col-lg-8 col-lg-offset-2
                col-md-10 col-md-offset-1
                sidebar-container">

                <!-- Featured Tags -->
                

                <!-- Friends Blog -->
                
            </div>
        </div>

    </div>
</article>
<!-- 网易云音乐-->

<iframe class="cloud-music" frameborder="no" border="0" marginwidth="0" marginheight="0" width=330 height=86 
    src="//music.163.com/outchain/player?type=2&amp;id=18803411&amp;auto=0&amp;height=66">
</iframe>
<!-- 网易云跟帖-->
<script src="https://img1.cache.netease.com/f2e/tie/yun/sdk/loader.js"></script>
<script>
var cloudTieConfig = {
  url: document.location.href, 
  sourceId: "",
  productKey: "40a8ee22b6084862a8907e6902e525fa",
  target: "cloud-tie-wrapper"
};
var yunManualLoad = true;
Tie.loader("aHR0cHM6Ly9hcGkuZ2VudGllLjE2My5jb20vcGMvbGl2ZXNjcmlwdC5odG1s", true);
</script>

<!-- Footer -->
<!-- Footer -->
<footer>
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1 text-center">
                <p class="copyright text-muted">
                    Copyright &copy; MillZhang 2017
                    <br>
                </p>
            </div>
        </div>
    </div>
</footer>

<!-- jQuery -->
<script src="/js/jquery.min.js"></script>

<!-- Bootstrap Core JavaScript -->
<script src="/js/bootstrap.min.js"></script>

<!-- Custom Theme JavaScript -->
<script src="/js/blog.js"></script>

<!-- async load function -->
<script>
    function async(u, c) {
      var d = document, t = 'script',
          o = d.createElement(t),
          s = d.getElementsByTagName(t)[0];
      o.src = u;
      if (c) { o.addEventListener('load', function (e) { c(null, e); }, false); }
      s.parentNode.insertBefore(o, s);
    }
</script>

<!-- jquery.tagcloud.js -->
<script>
    // only load tagcloud.js in tag.html
    if($('#tag_cloud').length !== 0){
        async("http://oritfw5nq.bkt.clouddn.com/jquery.tagcloud.js",function(){
            $.fn.tagcloud.defaults = {
                //size: {start: 1, end: 1, unit: 'em'},
                color: {start: '#bbbbee', end: '#0085a1'},
            };
            $('#tag_cloud a').tagcloud();
        })
    }
</script>

<!--fastClick.js -->
<script>
    async("//cdn.bootcss.com/fastclick/1.0.6/fastclick.min.js", function(){
        var $nav = document.querySelector("nav");
        if($nav) FastClick.attach($nav);
    })
</script>



<!--wechat title img-->
<img class="wechat-title-img" src="http://oritfw5nq.bkt.clouddn.com/avatar.jpg?imageslim">
<a id="backtop" class="border-bottom" href="javascript:;">回顶部</a>
<script type="application/javascript">
var docOuter = document.body.scrollTop ? document.body : document.documentElement;
var backToTop = function(rate) {
  var doc = document.body.scrollTop ? document.body : document.documentElement;
  var scrollTop = doc.scrollTop;
  var top = function() {
    scrollTop = scrollTop + (0 - scrollTop) / (rate || 2);
    if (scrollTop < 1) {
      doc.scrollTop = 0;
      return;
    }
    doc.scrollTop = scrollTop;
    // 动画gogogo!
    requestAnimationFrame(top);
  };
  top();
};
var topBtn = document.getElementById('backtop'),
    docTop = docOuter.scrollTop;
if(docTop>=300){
  topBtn.style.opacity = 1;
}

topBtn.onclick = function() {
  backToTop(12)
}
window.onscroll = function(e) {
  var doc = document.body.scrollTop ? document.body : document.documentElement;
  var scrollTop = doc.scrollTop;
  if (scrollTop >= 300) {
    topBtn.style.opacity = 1;
  } else {
    topBtn.style.opacity = 0;
  }
}
</script>
</body>

</html>
